use crate::jwt::JWTToken;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
use std::default;

#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Getters, Setters, Default)]
#[getset(get = "pub", set = "pub")]
pub struct RequestModel {
  uid: Option<i64>,
  super_admin: Option<i32>,
  username: Option<String>,
  agency_code: Option<String>,
  product_code: Option<String>,
  path: Option<String>,
  from: Option<Source>,
  attachments: Option<HashMap<String, Value>>,
}

impl RequestModel {
  pub fn new(data: JWTToken, path: String) -> Self {
    let mut model = RequestModel::default();
    model.set_uid(Some(data.id().clone()));
    model.set_agency_code(Some(data.agency_code().clone()));
    model.set_super_admin(Some(data.super_admin().clone()));
    model.set_username(Some(data.username().clone()));
    model.set_path(Some(path));
    model.set_from(Some(data.from().clone()));
    model
  }
  pub fn setData(&mut self, data: JWTToken, path: String) {
    self.set_uid(Some(data.id().clone()));
    self.set_agency_code(Some(data.agency_code().clone()));
    self.set_super_admin(Some(data.super_admin().clone()));
    self.set_username(Some(data.username().clone()));
    self.set_path(Some(path));
    self.set_from(Some(data.from().clone()));
  }
  pub fn setDataForRequestModel(&mut self, data: RequestModel) {
    self.set_uid(data.uid().clone());
    self.set_agency_code(data.agency_code().clone());
    self.set_super_admin(data.super_admin().clone());
    self.set_username(data.username().clone());
    self.set_path(data.path().clone());
    self.set_from(data.from().clone());
    self.set_attachments(data.attachments().clone());
  }
  pub fn clear(&mut self) {
    self.set_uid(None);
    self.set_agency_code(None);
    self.set_super_admin(None);
    self.set_username(None);
    self.set_path(None);
    self.set_from(None);
    self.set_attachments(None);
  }
}

#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
pub enum Source {
  Admin, //管理端
  Wxapp, //微信小程序
  Pc,    //pc端
  Mp,    //微信公众号
}
impl default::Default for Source {
  fn default() -> Self {
    Source::Admin
  }
}
